/*----------------------------------------------------------------------------

	Copyright (c) 2006, Creator of the Cant Project.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	+ Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

	+ Redistributions in binary form must reproduce the above copyright notice,
	this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.

	+ Neither the name of the Creator of the Cant Project nor the names of its
	contributors may be used to endorse or promote products derived from this
	software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------*/

#include	"log.hpp"

#include	<iostream>



std::string			STR_VALUE1			= "$1";
std::string			STR_VALUE2			= "$2";
std::string			STR_VALUE3			= "$3";
std::string			STR_VALUE4			= "$4";


/**
	Default constructor.
	
*/
Log::Log(void )	: m_logMode(ltInfo )
{}


/**
	Constructor.
	
	@param		a_logMode		preferred logging mode.
*/
Log::Log(Log::Mode a_logMode )
{
	setMode(a_logMode );
}
		
		
/**
	Gives the current logging mode.

	@return		current logging mode.
*/
Log::Mode	Log::getMode()
{
	return	m_logMode;
}


/**
	Sets the current logging mode.
	
	@param		a_logMode		new logging mode.
*/
void	Log::setMode(Log::Mode a_logMode )
{
	m_logMode		= a_logMode;
}


void	Log::info(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2, const std::string& a_strValue3, const std::string& a_strValue4 ) const
{
	write(a_strMessage, a_strValue1, a_strValue2, a_strValue3, a_strValue4 );
}


void	Log::warning(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2, const std::string& a_strValue3, const std::string& a_strValue4 ) const
{
	if (m_logMode >= ltWarning )
	{
		write(a_strMessage, a_strValue1, a_strValue2, a_strValue3, a_strValue4 );
	}
}


void	Log::error(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2, const std::string& a_strValue3, const std::string& a_strValue4 ) const
{
	if (m_logMode >= ltError )
	{
		write(a_strMessage, a_strValue1, a_strValue2, a_strValue3, a_strValue4 );
	}
}


void Log::write(void )
{
	std::clog	<< endl;
}


void	Log::write(const std::string& a_strMessage )
{
	std::clog	<< a_strMessage
				<< std::endl;
}


void	Log::write(const std::string& a_strMessage, const std::string& a_strValue1 )
{
	std::string				strWrite		= Util::replace(a_strMessage, STR_VALUE1, a_strValue1 );
	
	write(strWrite );
}


void	Log::write(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2 )
{
	std::string				strWrite		= Util::replace(a_strMessage, STR_VALUE1, a_strValue1 );
	strWrite				= Util::replace(strWrite, STR_VALUE2, a_strValue2 );
	
	write(strWrite );
}


void	Log::write(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2, const std::string& a_strValue3 )
{
	std::string				strWrite		= Util::replace(a_strMessage, STR_VALUE1, a_strValue1 );
	strWrite				= Util::replace(strWrite, STR_VALUE2, a_strValue2 );
	strWrite				= Util::replace(strWrite, STR_VALUE3, a_strValue3 );
	
	write(strWrite );
}


void	Log::write(const std::string& a_strMessage, const std::string& a_strValue1, const std::string& a_strValue2, const std::string& a_strValue3, const std::string& a_strValue4 )
{
	std::string		strWrite		= Util::replace(a_strMessage, STR_VALUE1, a_strValue1 );
	strWrite		= Util::replace(strWrite, STR_VALUE2, a_strValue2 );
	strWrite		= Util::replace(strWrite, STR_VALUE3, a_strValue3 );
	strWrite		= Util::replace(strWrite, STR_VALUE4, a_strValue4 );
	
	write(strWrite );
}
